package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Models.YeastView;

public class YeastViewPresenter extends AbstractPresenter<YeastView> {
	final String SINGLEITEM = "yeastView";
	final String MULTIITEM = "yeastViews";
	
	public ArrayList<YeastView> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public YeastView tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public YeastView createItemFromJSONObject(JSONObject jsonObject){
		YeastView item = new YeastView();
		try{
			item.setYeastAdditionalPitchRate(jsonObject.getDouble("yeastAdditionalPitchRate"));
			item.setYeastBasePitchRate(jsonObject.getDouble("yeastBasePitchRate"));
			item.setYeastID(jsonObject.getInt("yid"));
			item.setYeastName(jsonObject.getString("yeastName"));
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(YeastView item){
		try{
			JSONObject json = new JSONObject();
			json.put("yeastAdditionalPitchRate", item.getYeastAdditionalPitchRate());
			json.put("yeastBasePitchRate", item.getYeastBasePitchRate());
			json.put("yid", item.getYeastID());
			json.put("yeastName", item.getYeastName());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public YeastView getEmptyEntity(){
		YeastView entity = new YeastView();
		return entity;
	}
}
